package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.CommodityDao;
import com.dao.EmployeeDao;
import com.dao.SellDao;
import com.pojo.Commodity;
import com.pojo.Employee;
import com.pojo.Sell;

@Service("SellService")
public class SellServiceImpl implements SellService {

	@Autowired
	private SellDao sellDao;
	@Autowired
	private EmployeeDao employeeDao;
	@Autowired
	private CommodityDao commodityDao;

	@Override
	public boolean addSell(Sell sell) {
		// TODO Auto-generated method stub
		boolean result=false;
		if (sell.getSell_Id() == null) {
			if (sellDao.addSellNotId(sell) > 0)
				result = true;
		} else {
			if (sellDao.addSell(sell) > 0)
				result = true;
		}
		return result;

	}

	@Override
	public boolean deletSellForId(Integer sell_id) {
		// TODO Auto-generated method stub
		boolean result;
		if (sellDao.deleteSellForId(sell_id) > 0)
			result = true;
		else
			result = false;
		return result;
	}

	@Override
	public Sell GetSell(Integer sell_id) {
		// TODO Auto-generated method stub
		return sellDao.selectSellForId(sell_id);
	}

	@Override
	public List<Sell> GetAllSell() {
		// TODO Auto-generated method stub
		return sellDao.selectAllSell();
	}

	@Override
	public boolean updateSell(Sell sell) {
		// TODO Auto-generated method stub
		boolean result;
		if (sellDao.deleteSellForId(sell.getSell_Id()) > 0 && sellDao.addSell(sell) > 0)
			result = true;
		else
			result = false;
		return result;
	}

	@Override
	public Employee GetEmployee(Integer employee_id) {
		// TODO Auto-generated method stub
		return employeeDao.selectEmployeeForId(employee_id);
	}

	@Override
	public Commodity GetCommodity(Integer commodity_id) {
		// TODO Auto-generated method stub
		return commodityDao.selectCommodityForId(commodity_id);
	}

}
